const sqlQuery = require("../db/db");
const { queryWordSql, insertWordAndPronSql } = require("../db/sql");
module.exports = {
  async findWord(ctx) {
    const word = ctx.request.body.data;
    if (typeof word !== "string") {
      ctx.throw(500, "请求数据类型错误");
    }
    console.log(`要查询的单词是 : ${word}`);
    const results = await sqlQuery(queryWordSql, word);
    const wordInfo = results[0];
    if (wordInfo && typeof wordInfo === "object") {
      const { id, english_word_id, phonetic_transcription, ...part_of_speech } =
        wordInfo;
      ctx.response.body = {
        id,
        phonetic_transcription,
        part_of_speech,
        word,
      };
    }
    // console.log(wordInfo);
  },
  async insertWord(ctx) {
    // sqlQuery(insertWordAndPronSql, []);
  },
};
